// app.js
App({
  onLaunch() {
    const bgAudio = wx.getBackgroundAudioManager()
    bgAudio.title = '背景音乐'
    bgAudio.src = 'http://music.163.com/song/media/outer/url?id=1431092646.mp3'
    
    this.globalData = {
      backgroundAudio: {
        manager: bgAudio,
        isPlaying: false
      }
    }
    
    // 统一状态更新函数
    const updateState = (isPlaying) => {
      this.globalData.backgroundAudio.isPlaying = isPlaying
    }
    
    bgAudio.onPlay(() => updateState(true))
    bgAudio.onPause(() => updateState(false))
    bgAudio.onStop(() => updateState(false))
    bgAudio.onError(console.error)
  },
  
  globalData: {}
})